REM >Director:Menus.System.LERecall

REM This makes a menu of the lineeditor history.
REM Original by Dan Ellis

ON ERROR: PROCerror
debug=FALSE
IF debug THEN TRACE TO "Pipe:err"

Menu=FNswi_number("Director_Menu")
EndMenu=FNswi_number("Director_EndMenu")
Option=FNswi_number("Director_Option")
Command=FNswi_number("Director_Command")
Dash=FNswi_number("Director_Dash")

SYS Menu,"LineEditorHistory -temp"

pipe$ = "Pipe:LineEditor.History"

OSCLI("SaveHistory "+pipe$)
h% = OPENIN pipe$
IF h% <> 0 THEN
  WHILE h% AND NOTEOF#h%
    line$ = ""
    a$ = CHR$ BGET#h%
    WHILE a$ > CHR$31
      line$ += a$
      a$ = CHR$ BGET#h%
    ENDWHILE
    REM double up any quotes
    quote%=INSTR(line$,"""")
    WHILE quote%
      line$=LEFT$(line$,quote%)+MID$(line$,quote%)
      quote%=INSTR(line$,"""",quote%+2)
    ENDWHILE
    realline$ = """"+line$+""""
    IF debug THEN BPUT#TRACE, realline$
    SYS Option, realline$
    SYS Command, "TaskWindow -quit "+realline$
    REM SYS Command, "ProcessKeys "+realline$
  ENDWHILE
ENDIF
CLOSE# h%

SYS EndMenu

*Set Director$Menu LineEditorHistory

END

DEF FNswi_number(name$)
  SYS "OS_SWINumberFromString",,name$ TO A%
=A%

DEF PROCerror
  IF h% CLOSE#h%
  ON ERROR OFF
  ERROR ERR,REPORT$+" at "+STR$ ERL
ENDPROC

